﻿<?php
class Stock {
	//NhÃ¢Ì£p mÃ´Ì£t Stock vaÌ€o danh saÌ�ch
	public function setStock($scode,$sprice,$sname)
	{
		include $_SERVER['DOCUMENT_ROOT'].'scue'.'/configuration.php';
		$scode = mysql_real_escape_string($scode);
		$sprice = mysql_real_escape_string($sprice);
		$sname = utf8_encode(mysql_real_escape_string($sname));
		$sql = "INSERT INTO stock VALUES (NULL, '$scode',$sprice,'$sname')";
		if(!($result = mysql_query($sql)))
		die(mysql_error());
		
	}
	//KiÃªÌ‰m tra xem coÌ� stock Ä‘oÌ� chÆ°a
	public function isAlready($code)
	{
		include $_SERVER['DOCUMENT_ROOT'].'scue'.'/configuration.php';
		$sql = "SELECT StockID FROM stock WHERE (Code ='$code')";
		if(!($result = mysql_query($sql))) die(mysql_error());
		$nRow = mysql_num_rows($result);
		if ($nRow > 0)
		return true;
		return false;
	}

	//In thÃ´ng tin cá»• phiáº¿u trong lÃºc nháº­p tu broker
	private function printInformationStock($row)
	{
		echo "<p>ID : ".$row['StockID']."</p>";
		echo "<input type='hidden' name='stockid' id='stockid' value='".$row['StockID']."'/>";
		echo "<p>Name: ".$row['Name']."</p>";
		$price = floatval($row['Price']);
		echo "<p>GiaÌ� cao nhÃ¢Ì�t: ";
		echo (string)($price * 1.1)."</p>";
		echo "<input type='hidden' id='pricemax' value='".(string)($price * 1.1)."'/>";
		echo "<p>GiaÌ� thÃ¢Ì�p nhÃ¢Ì�t: ";
		echo (string)($price * 0.9)."</p>";
		echo "<input type='hidden' id='pricemin' value='".(string)($price * 0.9)."'/>";
	}

	//TiÌ€m tÃªn cÃ´ng ty cÃ´Ì‰ phiÃªÌ�u thÃ´ng qua MaÌƒ cÃ´Ì‰ phiÃªÌ�u
	public function findNameStockByCode($code)
	{
		include $_SERVER['DOCUMENT_ROOT'].'scue'.'/configuration.php';
		$sql = "SELECT * FROM stock WHERE (Code ='$code')";
		if(!($result = mysql_query($sql))) die(mysql_error());
		$row = mysql_fetch_array($result);
		$this->printInformationStock($row);
	}

	//TiÌ€m MaÌƒ cÃ´Ì‰ phiÃªÌ�u thÃ´ng qua ID
	public function findCodeStockByID($id)
	{
		include $_SERVER['DOCUMENT_ROOT'].'scue'.'/configuration.php';
		$sql = "SELECT * FROM stock WHERE (StockID ='$id')";
		if(!($result = mysql_query($sql))) die(mysql_error());
		$row = mysql_fetch_array($result);
		return $row['Code'];
	}

	//TiÌ€m ID cÃ´Ì‰ phiÃªÌ�u thÃ´ng qua Code
	public function findIDStockByCode($code)
	{
		include $_SERVER['DOCUMENT_ROOT'].'scue'.'/configuration.php';
		$sql = "SELECT * FROM stock WHERE (Code ='$code')";
		if(!($result = mysql_query($sql))) die(mysql_error());
		$row = mysql_fetch_array($result);
		return $row['StockID'];
	}
}
?>